package common

import (
	"math/rand"
	"strconv"
	"strings"
	"time"
)

var defaultLetters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")

func JoinString(args ...string) string {
	var build strings.Builder
	for _, value := range args {
		build.WriteString(value)
	}
	return build.String()
}

// RandomString returns a random string with a fixed length
func RandomString(n int, allowedChars ...[]rune) string {
	var letters []rune

	if len(allowedChars) == 0 {
		letters = defaultLetters
	} else {
		letters = allowedChars[0]
	}

	b := make([]rune, n)
	for i := range b {
		b[i] = letters[rand.Intn(len(letters))]
	}
	now := time.Now().UnixMicro()
	strnow := strconv.FormatInt(now, 10)
	return string(b) + "-" + strnow
}
